#include "esptimer.h"


/**
 * @brief       定时器回调函数
 * @param       arg: 不携带参数
 * @retval      无
 */
void esptimer_callback(void* arg){
    LED_TOGGLE();
}

/**
 * @brief       初始化高分辨率定时器(ESP_TIMER)
 * @param       tps: 定时器周期,以微秒为单位(μs).
 *              若以一秒为定时器周期来执行一次定时器中断,那此处tps = 1s = 1000000μs
 * @retval      无
 */
void esptimer_init(uint64_t tps)
{
    esp_timer_handle_t timer_handle;
    esp_timer_create_args_t timer_arg={
        .callback= esptimer_callback,
        .arg=NULL,
        .dispatch_method=ESP_TIMER_TASK,
        .name="Timer",
    };
    
    ESP_ERROR_CHECK(esp_timer_create(&timer_arg,&timer_handle));
    ESP_ERROR_CHECK(esp_timer_start_periodic(timer_handle,tps));

}